<!--
 * @FileDescription: hr录入已注册员工表单
 * @Author: 叶永鸿、袁年政
 * @Date: 2021-7-17
 * @LastEditors: 叶永鸿
 * @LastEditTime: 2021-7-18
 -->
<template>
  <el-container>
    <el-header style="text-align: center">
      <el-input
        v-model="logEmpSearchTel"
        placeholder="请输入员工电话"
        style="width: 50%"
        @keyup.enter.="logEmpSearchSubmit"
      >
        <template #append>
          <el-button type="primary" @click="logEmpSearchSubmit">搜索</el-button>
        </template>
      </el-input>
    </el-header>
    <el-main v-if="isSearched">
      <div>
        <el-space direction="vertical">
          <!--基础信息卡片-->
          <el-card style="width: 1000px">
            <template #header>
              <span>个人信息</span>
              <div style="text-align: right">
                <el-button class="button" type="text" @click="logEmpSearchConfirm">录入</el-button>
              </div>
            </template>
            <div>
              <el-descriptions
                class="margin-top"
                :column="3"
                :size="size"
                border
              >
                <el-descriptions-item>
                  <template #label>
                    <i class="el-icon-user"></i>
                    姓名
                  </template>
                  {{ logEmpInfor.realname }}
                </el-descriptions-item>
                <el-descriptions-item>
                  <template #label>
                    <i class="el-icon-s-custom"></i>
                    性别
                  </template>
                  {{ logEmpInfor.gender }}
                </el-descriptions-item>
                <el-descriptions-item>
                  <template #label>
                    <i class="el-icon-mobile-phone"></i>
                    电话号码
                  </template>
                  {{ logEmpInfor.telephone }}
                </el-descriptions-item>
                <el-descriptions-item>
                  <template #label>
                    <i class="el-icon-date"></i>
                    邮箱
                  </template>
                  {{ logEmpInfor.email }}
                </el-descriptions-item>
                <el-descriptions-item>
                  <template #label>
                    <i class="el-icon-tickets"></i>
                    职位
                  </template>
                  <el-input v-model="emploeePosition">请输入职位</el-input>
                </el-descriptions-item>
                <el-descriptions-item>
                  <template #label>
                    <i class="el-icon-tickets"></i>
                    年薪(万)
                  </template>
                  <el-input v-model="emploeeSalary" rule:>请输入年薪</el-input>
                </el-descriptions-item>
              </el-descriptions>
              <el-divider></el-divider>
              <el-table border :data="logEmpExprenceInfor">
                <el-table-column type="expand">
                  <template #default="">
                    <el-form
                      label-position="left"
                      inline
                      class="demo-table-expand"
                    >
                      <el-form-item label="评价">
                        <span>{{ logEmpExprenceInfor.evaluation }}</span>
                      </el-form-item>
                    </el-form>
                  </template>
                </el-table-column>
                <el-table-column prop="companyname" label="公司名" width="180">
                </el-table-column>
                <el-table-column prop="recruited" label="入职时间" width="190">
                </el-table-column>
                <el-table-column prop="suspended" label="离职时间" width="190">
                </el-table-column>
                <el-table-column prop="position" label="职位" width="220">
                </el-table-column>
                <el-table-column prop="salary" label="年薪（万）" width="130">
                </el-table-column>
              </el-table>
            </div>
          </el-card>
        </el-space>
      </div>
    </el-main>
  </el-container>
</template>

<script>
export default {
  name: "logEmpExp",

  data() {
    return {
      logEmpSearchTel: "",
      logEmpInfor: {},
      isSearched: false,
      logEmpExprenceInfor: [],
      emploeeSalary: "",
      emploeePosition: "",
    };
  },

  methods: {
    logEmpSearchSubmit() {
      var that = this;
      var ifFree = false;
      this.$axios
        .get("http://47.100.167.206:8082/Modify/confirm", {
          params: {
            telephone: this.logEmpSearchTel,
          },
          headers: {
            token: that.$store.state.loginInfor.token,
          },
        })
        .then(
          function (response) {
            if (response.data.message == "existemployee") {
              console.log(response);
              that.$axios
                .get("http://47.100.167.206:8082/Modify/searchEmp", {
                  //获取就职信息卡片
                  params: {
                    telephone: that.logEmpSearchTel,
                  },
                  headers: {
                    token: that.$store.state.loginInfor.token,
                  },
                })
                .then(
                  function (response) {
                    console.log(response);
                    that.logEmpInfor = response.data.data;
                    //that.isSearched = true;
                  },
                  function (err) {
                    console.log("寄");
                  }
                );
              that.$axios
                .get("http://47.100.167.206:8082/Query/searchone", {
                  //获取就职经历
                  params: {
                    tel: that.logEmpSearchTel,
                  },
                  headers: {
                    token: that.$store.state.loginInfor.token,
                  },
                })
                .then(
                  function (response) {
                    console.log(response);
                    that.logEmpExprenceInfor = response.data.data;
                    that.isSearched = true;
                  },
                  function (err) {
                    console.log("寄");
                  }
                );
            } else {
              that.$message({
                type: "error",
                message: "该员工目前不是自由人，请检查手机号码是否正确",
              });
              that.isSearched = false;
            }
          },
          function (err) {
            console.log(err);
            that.isSearched = false;
          }
        );
    },
    logEmpSearchConfirm() {
      var that = this;
      if (this.emploeePosition != "" && this.emploeeSalary != "") {
        this.$axios
          .get("http://47.100.167.206:8082/Modify/recruitEmp", {
            params: {
              telephone: this.logEmpSearchTel,
              position: this.emploeePosition,
              salary: this.emploeeSalary,
            },
            headers: {
              token: this.$store.state.loginInfor.token,
            },
          })
          .then(
            function (response) {
              if (response.data.message == "successsrecruited") {
                that.$message({
                  type: "success",
                  message: "成功录入",
                });
                console.log(response);
              } else {
                that.$message({
                  type: "error",
                  message: "录入失败，请重新登录",
                });
              }
            },
            function (err) {
              that.$message({
                type: "error",
                message: "网络请求错误，录入失败",
              });
              console.log("又寄！");
            }
          );
      } else {
        that.$message({
          type: "error",
          message: "职位信息或年薪不能为空，请输入",
        });
      }
    },
  },
};
</script>
